const app = getApp();

Page({
  goto: app.goto,

  /**
   * 页面的初始数据
   */
  data: {
    mrRomm: wx.getStorageSync("mrRomm"),
    nameCommunity: wx.getStorageSync("nameCommunity"),
    phone:"",
    effective:[],
    invalid:[],

    effective_list: [],
    invalid_list: [],
    examine_list: [],
    reject_list: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(this.data.mrRomm);
    app.init(this);
    if (wx.getStorageSync("phone") != "" && wx.getStorageSync("phone") != undefined){
      this.setData({
        phone: wx.getStorageSync("phone"),
      })
      this.client_parkingFee_getMyCars();
    }else{
      app.api.client_user_getUserPhone({
        token: wx.getStorageSync('token'),
      }, (res) => {
        wx.setStorageSync('phone', res.data)
        this.setData({
          phone: res.data
        })
        this.client_parkingFee_getMyCars();
      })
    }
    
  },

  client_parkingFee_getMyCars: function () {
    
    app.api.client_parkingFee_getMyCars({
      token: wx.getStorageSync('token'),
      idCommunity: wx.getStorageSync('idCommunity'),
      phone: this.data.phone,
    }, (res) => {
      
      let data = res.data;
      let effective_list =  [];
      let invalid_list = [];
      let examine_list = [];
      let reject_list = [];

      for(let i in data){

        // 1有效，2无效，0审核中，-1申请被驳回
        if(data[i].status == 1){
          effective_list.push(data[i]);
        }
        else if (data[i].status == 2){
          invalid_list.push(data[i]);
        }
        else if (data[i].status == 0) {
          examine_list.push(data[i]);
        }
        else if (data[i].status == -1) {
          reject_list.push(data[i]);
        }

      }

      this.setData({
        effective_list: effective_list,
        invalid_list: invalid_list,
        examine_list: examine_list,
        reject_list: reject_list,
      })

      // this.setData({
      //   parkingFeeProject: res.data
      // })
      // if (res.status == -1) {
      //   app.toast(res.msg);
      // }
    })

  },

  goto_car_pay: function (e) {

    console.log(e.currentTarget.dataset.item);


    wx.navigateTo({
      url: '../car_pay/car_pay?type=1'
        + "&item=" + JSON.stringify(e.currentTarget.dataset.item)
    })

  },

  goto_car_recharge_record: function (e) {
    console.log(e.currentTarget.dataset.item);
    wx.navigateTo({
      url: '../car_recharge_record/car_recharge_record?id=' + e.currentTarget.dataset.item.id
        + "&item=" + JSON.stringify(e.currentTarget.dataset.item)
    })
  },


  

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

})